package com.main.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全球异常
 *
 * @author RuoYu
 * @date 2022/09/26
 */
@Slf4j
@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(CustomException.class)
    public R<String> ex(CustomException e) {
        log.error(e.getMessage());
        return R.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R<String> ex2(Exception e) {
        log.error(e.getMessage());
        return R.error("服务器内部异常");
    }
}
